/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bio.jpa.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Diego
 */
@Entity
@Table(name = "group", catalog = "biodb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "UserGroup.findAll", query = "SELECT u FROM UserGroup u"),
    @NamedQuery(name = "UserGroup.findByGrId", query = "SELECT u FROM UserGroup u WHERE u.grId = :grId"),
    @NamedQuery(name = "UserGroup.findGroupsInotIn", query = " select g from UserGroup g where g.grId not in (SELECT m.userHasGroupPK.gidFk  FROM UserHasGroup m where m.userHasGroupPK.uidFk=:userId) "),
    @NamedQuery(name = "UserGroup.findMyGroups", query = " select g from UserGroup g where g.grId in (SELECT m.userHasGroupPK.gidFk  FROM UserHasGroup m where m.userHasGroupPK.uidFk=:userId) "),
    @NamedQuery(name = "UserGroup.findByGrDesc", query = "SELECT u FROM UserGroup u WHERE u.grDesc = :grDesc")})
public class UserGroup implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Basic(optional = false)
    @Column(name = "gr_id")
    private Integer grId;
    @Basic(optional = false)
    @Size(min = 1, max = 45)
    @Column(name = "gr_desc")
    private String grDesc;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "userGroup")
    private GroupPrevilege groupPrevilege;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userGroup")
    private Collection<UserHasGroup> userHasGroupCollection;

    public UserGroup() {
    }

    public UserGroup(Integer grId) {
        this.grId = grId;
    }

    public UserGroup(Integer grId, String grDesc) {
        this.grId = grId;
        this.grDesc = grDesc;
    }

    public Integer getGrId() {
        return grId;
    }

    public void setGrId(Integer grId) {
        this.grId = grId;
    }

    public String getGrDesc() {
        return grDesc;
    }

    public void setGrDesc(String grDesc) {
        this.grDesc = grDesc;
    }

    public GroupPrevilege getGroupPrevilege() {
        return groupPrevilege;
    }

    public void setGroupPrevilege(GroupPrevilege groupPrevilege) {
        this.groupPrevilege = groupPrevilege;
    }

    @XmlTransient
    public Collection<UserHasGroup> getUserHasGroupCollection() {
        return userHasGroupCollection;
    }

    public void setUserHasGroupCollection(Collection<UserHasGroup> userHasGroupCollection) {
        this.userHasGroupCollection = userHasGroupCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (grId != null ? grId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserGroup)) {
            return false;
        }
        UserGroup other = (UserGroup) object;
        if ((this.grId == null && other.grId != null) || (this.grId != null && !this.grId.equals(other.grId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bio.jpa.entities.Group1[ grId=" + grId + " ]";
    }
    
}
